#ifndef _LJMU_WINDOWS_APP_H_
#define _LJMU_WINDOWS_APP_H_

//Lets Define the Windows 32 Lean and Mean Configuration to optimise our win 32 API for games
#define WIN32_LEAN_AND_MEAN

//This is an Win 32 App - so we need to include the Windows Header File!!
#include <windows.h>
#include <WindowsX.h>

//Forward Declaration of the CDX10BaseApplication Class - we are going to be deriving this from our concrete application instance
class CDX10BaseApplication;

/******************************************
* Class to Represent a Windows 32 Based 
* Application, and provide the means to
* link it with our direct X API.  The class
* hooks into the WinMain and WinProc functions
* and routes all windows messages and events
* through to our application.
*
* AUTHOR:  CHRIS CARTER
*******************************************/
class CDX10WindowsApplication
{
	public:
		//------------CONSTRUCTORS AND DESTRUCTORS------------------------------------
		
		//Constructor which takes the concrete instance of our game application and initialises the Windows Objects to NULL.
		CDX10WindowsApplication(CDX10BaseApplication* pbaseapp): _obj_baseapp(pbaseapp), _obj_h_instance(NULL),_obj_h_wnd(NULL){}
		~CDX10WindowsApplication(){}							//Empty Destructor 

		//------------PUBLIC METHODS--------------------------------------------------
		bool initialise();								//Initialises the Base Application
		void cleanup();									//Cleans up the Application by destroying all dynamic objects
		void appStart();								//Starts the Game Loop Processing

		//------------ACCESSORS/MUTATORS----------------------------------------------
		CDX10BaseApplication* getBaseApp();				//Returns the 
		HINSTANCE getAppInstance();						//Returns the Application Instance Handle
		HWND getWindowHandle();							//Returns the Application Window Handle
	
	private:
		//------------PRIVATE METHODS-------------------------------------------------
		bool internGameLoop();							//Handles the Game Loop by calling the methods of the Game Class
		void internInitWindows();						//Initialises the Windows Application Window and associated objects
		void internCleanupWindows();					//Cleans up the Windows Application Window and associated objects

	private:
		//------------INTERNAL FIELD MEMBERS------------------------------------------
		HINSTANCE					_obj_h_instance;	//Handle to the Application Instance
		HWND						_obj_h_wnd;			//Handle to the Application Window
		CDX10BaseApplication*		_obj_baseapp;		//Pointer to the Game Application Class
};

//----------------INLINE GETTERS------------------------------------------------------

/******************************************
* Returns a Pointer to our Concrete game
* Implementation as a Base Application Instance.
******************************************/
inline CDX10BaseApplication* CDX10WindowsApplication::getBaseApp()
{
	return this->_obj_baseapp;
}

/******************************************
* Returns a Handle to our Application Instance.
******************************************/
inline HINSTANCE CDX10WindowsApplication::getAppInstance()
{
	return this->_obj_h_instance;
}

/******************************************
* Returns a Handle to Our Application Window.
******************************************/
inline HWND CDX10WindowsApplication::getWindowHandle()
{
	return this->_obj_h_wnd;
}

//-----STATIC GLOBALS TO REPRESENT OUR WIN PROC HANDLING AND OUR APPLICATION HANDLE
static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
static CDX10BaseApplication* g_base_app;

#endif